import  { lang } from '@/utils/lang'
// import SeqTitle from '@/components/g-ui/g-vxe-grid/seq-title.vue'
export const VxeGridMixin = {
  data() {
    return {
      gridOptions: {
        rowConfig: {
          useKey: true , isCurrent: true, isHover: true
        },
        columnConfig: {
          resizable : true
        },
        border: true ,
        height: 'auto',
        autoResize:true,
        data: []
      }
    }
  },
  methods: {
    getDefaultTableColsConfig(colsConfig) {
      if (Array.isArray(colsConfig)) {
        return colsConfig.map((col, index) => {
          if(['checkbox', 'radio', 'seq'].includes(col.type)) {
            return getCheckoutDefaultConfig(col)
          } else if (col.type === 'options') {
            return getOptionsDefaultConfig(col)
          }
          if(colsConfig.formatter && typeof colsConfig.formatter === 'function'){
            colsConfig.formatter.bind(this)
          }
          return {
            align: 'center',
            showOverflow: true,
            showHeaderOverflow: true,
            sortable: false,
            minWidth: 60,
            ...col
          }
        })
      }
      return []
    },
    buttonEventEmit(buttonCode, searchFormData) {
      if (buttonCode === 'QueryPage') {
        this.searchQuery(searchFormData)
      }
    },
    pageSizeChange(pageNo, pageSize) {
      this.gridOptions.pagination.pageNo = pageNo
      this.gridOptions.pagination.pageSize = pageSize
      this.searchQuery()
    },
    pageNoChange(pageNo) {
      console.log(pageNo)
      this.gridOptions.pagination.pageNo = pageNo
      this.searchQuery()
    }
  }
}
export const getCheckoutDefaultConfig = (colConfig = {}) => {
  const DefaultConfig = {
    width: 50,
    fixed: 'left',
    align: 'center',
    ...colConfig
  }
  if (colConfig.type === 'seq') {
    return {
      title: '序号',
      ...DefaultConfig,
      slots: {
        header: ({row}) => {
          return [
            '#'
          ]
        }
      }
    }
  } else if (colConfig.type === 'radio') {
    return {
      title: '单选',
      ...DefaultConfig,
      width: 56,
      slots: {
        header: ({row}) => {
          return [
            '单选'
          ]
        }
      }
    }
  }
  return DefaultConfig
}
export const getOptionsDefaultConfig = (colConfig = {}) => {
  return {
    width: 80,
    align: 'center',
    title: lang('操作'),
    fixed: 'right',
    ...colConfig
  }
}
export default { VxeGridMixin }
